package pl.edu.agh.io.gpstracker.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import pl.edu.agh.io.gpstracker.client.dto.MessagesDto;
import pl.edu.agh.io.gpstracker.dao.MessageDao;
import pl.edu.agh.io.gpstracker.model.Messages;

@Service
public class MessageServiceImpl extends GenericService<Messages, MessagesDto>
		implements MessageService {

	@Autowired
	private MessageDao messageDao;

	public MessageServiceImpl() {
		super(Messages.class, MessagesDto.class);
	}

	@Transactional
	public void sendMessage(MessagesDto message) throws DataAccessException {
		messageDao.saveOrUpdate(mapDto(message));
	}

	public List<MessagesDto> redMessagesByUserid(Integer userId)
			throws DataAccessException {
		return mapEntityList(messageDao.getMessageByUserId(userId));
	}
}
